package com.kude.dao;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kude.entity.ProductCategoryPrefix;


/**
 * A data access object (DAO) providing persistence and search support for
 * ProductCategoryPrefix entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see common.dao.ProductCategoryPrefix
 * @author MyEclipse Persistence Tools
 */

public class ProductCategoryPrefixDAO extends BaseDAO<ProductCategoryPrefix,Integer> {
	private static final Logger log = LoggerFactory
			.getLogger(ProductCategoryPrefixDAO.class);
	// property constants
	public static final String PRODUCT_PREFIX_NAME = ProductCategoryPrefix.PREFIXNAME;
	public static final String PRODUCT_PREFIX = ProductCategoryPrefix.PREFIX;

	public ProductCategoryPrefixDAO() {
		super(ProductCategoryPrefix.class);
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ProductCategoryPrefix instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ProductProfix as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByPrefixName(Object productProfixName) {
		return findByProperty(PRODUCT_PREFIX_NAME, productProfixName);
	}

	public List findAll() {
		log.debug("finding all ProductCategoryPrefix instances");
		try {
			String queryString = "from ProductCategoryPrefix";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ProductCategoryPrefix merge(ProductCategoryPrefix detachedInstance) {
		log.debug("merging ProductCategoryPrefix instance");
		try {
			ProductCategoryPrefix result = (ProductCategoryPrefix) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ProductCategoryPrefix instance) {
		log.debug("attaching dirty ProductCategoryPrefix instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ProductCategoryPrefix instance) {
		log.debug("attaching clean ProductCategoryPrefix instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}